package org.yty.travelagencyredis.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.yty.travelagencyredis.model.DTO.HistoryGroupMessageQueryDTO;
import org.yty.travelagencyredis.model.Entity.GroupMessage;
import org.yty.travelagencyredis.model.Entity.Result;
import org.yty.travelagencyredis.service.GroupMessageService;

import java.util.List;


@RestController
@RequestMapping("/group-message")
@RequiredArgsConstructor
public class GroupMessageController {
    private final GroupMessageService groupMessageService;

    @GetMapping("/{chatGroupId}")
    public Result<List<GroupMessage>> getMessages(@PathVariable Long chatGroupId) {
        List<GroupMessage> page = groupMessageService.getMessages(chatGroupId);
        return Result.ok(page);
    }

    @GetMapping("/history")
    public Result<List<GroupMessage>> getHistoryMessages(@ModelAttribute HistoryGroupMessageQueryDTO historyGroupMessageQueryDTO) {
        List<GroupMessage> page = groupMessageService.getHistoryMessages(historyGroupMessageQueryDTO);
        return Result.ok(page);
    }

    @PostMapping
    public Result<Void> sendGroupMessage(@RequestBody GroupMessage groupMessage){
        this.groupMessageService.save(groupMessage);
        return Result.ok();
    }
}
